<template>
  <div class="c-info-chat">
    <div class="c-info-chat__wraper" @click="AtComment">
      <div class="comment" v-for="comment, index in firend?.msgList" :key="comment?.id" ref="comments">
        <div class="comment__date" v-if="true">2024年4月20日 20:22</div>
        <!-- v-text="commrnt.time" -->
        <div class="comment__main" :class="{ 'is_my': comment.isMy, 'is-out': !comment.isMy }">
          <Images class="u-avatar comment__avatar" :src="comment.isMy ? user.avatar : firend.user.avatar" />
          <div class="comment__content">
            <div class="comment__username" v-if="!comment.isMy" v-text="comment.username"></div>
            <div class="comment__context" v-html="comment.content"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import Images from '@/components/Images/Index.vue';
import { onUpdated, useTemplateRef } from 'vue';
import { storeToRefs } from 'pinia'
import { useUserStore } from '@/pinia/userStore.js'

const { firend } = defineProps({
  firend: {
    type: Object,
    default: [],
  }
})
const emits = defineEmits(["scrollItem"]);

const { user } = storeToRefs(useUserStore());

const comments = useTemplateRef("comments")


function format (preTime, currentTime) {

}

function AtComment (e) {
  console.log(e.target.tagName);
  const elm = e.target;
  if (elm.tagName === "AT") {//是at元素
    //跳转路由
    // 跳转到xxx页面
  }
}



</script>

<style lang="scss" scoped>
// .c-info-chat {}

.c-info-chat__wraper {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.comment {
  display: flex;
  flex-direction: column;
  padding: 0 16px;
  margin-bottom: 16px;
  background-color: #F5F5F5;
  border-radius: 4px;
}

.is_my {
  flex-direction: row-reverse;

  .comment__context {
    background-color: #95ec69;

    &::before {
      border-left-color: #95ec69;
      right: -14px;
    }
  }
}

.comment__main {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}

.comment__content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.comment__username {
  font-size: 14px;
  color: #888;
  text-align: left;
}

.comment__date {
  color: white;
  background-color: #dadada;
  width: max-content;
  margin: 0 auto;
  padding: 2px 8px;
  border-radius: 2px;
}

.comment__context {
  margin-top: 16px;
  background-color: white;
  padding: 6px 10px;
  max-width: 260px;
  white-space: pre-wrap;
  word-wrap: break-word;
  text-align: left;
  position: relative;
  display: flex;
  align-items: center;

  &::before {
    content: "";
    position: absolute;
    border: 8px solid transparent;
    top: 50%;
    transform: translateY(-50%);
  }
}

.is-out {
  .comment__context {
    &::before {
      border-right-color: white;
      left: -14px;
    }
  }
}
</style>